#!/bin/sh
#*********************************************************************
#   Copyright (c) International Business Machines  Corp., 2000
#
#   This program is free software;  you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#   the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program;  if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
#  FILE   : cron
#
#  PURPOSE: Test a bad (negative) cron job
#			- try to edit the crontab of root
#   		- try to set illegal or nondefined execution times
#      	 	  Here the script uses file illegal_cron_lines which contains two
#      		  fields per line: the cron line to be tested (without script name),
#      		  and the description of this test. The description is written to
#      		  stdout during execution of the test.
#    		- try to do things you aren't allowed as non-root (cron runs as root)

#
#  HISTORY:
#     	SUSE
#


TEST_USER="c02_user"
TEST_USER_GROUP="users"
TEST_USER_HOMEDIR="/home/$TEST_USER"

#-----------------------------------------------------------------------
# FUNCTION:  do_setup
#-----------------------------------------------------------------------

do_setup(){

    #erase user if he may exist , so we can have a clean env
        rm -rf /home/$TEST_USER
        userdel $TEST_USER
	sleep 1

        useradd -m -g $TEST_USER_GROUP $TEST_USER
        if [ $? != 0 ]
        then {
                echo "Could not add test user $TEST_USER to system $RHOST."
                exit 1
        }
        fi
        # restart cron daemon
	# Red Hat uses crond, SuSE/Other uses cron.
	if [ -f /etc/init.d/crond ]; then
		/etc/init.d/crond restart
	else
		/etc/init.d/cron restart
	fi
}

#-----------------------------------------------------------------------
# FUNCTION:  do_cleanup
#-----------------------------------------------------------------------

do_cleanup(){
        rm -rf /home/$TEST_USER
        userdel $TEST_USER
}

#-----------------------------------------------------------------------
# FUNCTION:  MAIN
#-----------------------------------------------------------------------
do_setup
cron_neg_tests.sh $TEST_USER
EXIT_CODE=$?
do_cleanup
exit $EXIT_CODE
